package com.mall.controller;


import com.mall.pojo.GoodsPo;
import com.mall.service.GoodsService;
import com.mall.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author zhangshiqi
 * @since 2020-09-13
 */
@RestController
@RequestMapping("/goods/")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    /**分页查询商品数据*/
    @RequestMapping("doFindPageObject")
    public SysResult doFindPageObject(String username, Integer pageCurrent){
        return SysResult.success(goodsService.doFindPageObject(username, pageCurrent));
    }

    /**根据ID查询商品数据*/
    @RequestMapping("doFindGoodsById")
    public SysResult doFindGoodsById(Integer id){
        return SysResult.success(goodsService.doFindGoodsById(id));
    }

    /**将商品数据放入回收站*/
    @RequestMapping("doRecycleObjects")
    public SysResult doRecycleObjects(String ids){
        goodsService.doRecycleObjects(ids);
        return SysResult.success();
    }

    /**新增商品数据*/
    @RequestMapping("doAddObjects")
    public SysResult doAddObjects(GoodsPo goodsPo){
        goodsService.doAddObjects(goodsPo);
        return SysResult.success();
    }

    /**修改商品数据*/
    @RequestMapping("doUpdateObjects")
    public SysResult doUpdateObjects(GoodsPo goodsPo){
        System.out.println(goodsPo);
        goodsService.doUpdateObjects(goodsPo);
        return SysResult.success();
    }

    /**分页查询回收站商品数据*/
    @RequestMapping("doFindRecycleObjects")
    public SysResult doFindRecycleObjects(String username, Integer pageCurrent){
        return SysResult.success(goodsService.doFindRecycleObjects(username, pageCurrent));
    }

    /**删除回收站商品数据*/
    @RequestMapping("doDeleteRecycleObjects")
    public SysResult doDeleteRecycleObjects(String ids){
        goodsService.doDeleteRecycleObjects(ids);
        return SysResult.success();
    }

    /**恢复回收站中商品数据*/
    @RequestMapping("doRecoveryObjects")
    public SysResult doRecoveryObjects(String ids){
        goodsService.doRecoveryObjects(ids);
        return SysResult.success();
    }

    /**上架商品*/
    @RequestMapping("doChangeDisplayTrue")
    public SysResult doChangeDisplayTrue(String ids){
        goodsService.doChangeDisplayTrue(ids);
        return SysResult.success();
    }

    /**下架商品*/
    @RequestMapping("doChangeDisplayFalse")
    public SysResult doChangeDisplayFalse(String ids){
        goodsService.doChangeDisplayFalse(ids);
        return SysResult.success();
    }

    /**根据商品状态显示商品*/
    @RequestMapping("doSelectByState")
    public SysResult doSelectByState(String className,Integer pageCurrent){
        return SysResult.success(goodsService.doSelectByState(className,pageCurrent));
    }
}

